package cn.exrick.xboot.modules.workovertime.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.exrick.xboot.modules.workovertime.entity.HkOvertimeCollect;
import cn.exrick.xboot.modules.workovertime.mapper.HkOvertimeCollectMapper;
import cn.exrick.xboot.modules.workovertime.service.IHkOvertimeCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2023-09-22
 */
@Service
@Transactional
public class HkOvertimeCollectServiceImpl extends ServiceImpl<HkOvertimeCollectMapper, HkOvertimeCollect> implements IHkOvertimeCollectService {


    @Autowired
    private HkOvertimeCollectMapper hkOvertimeCollectMapper;

    @Override
    public IPage<HkOvertimeCollect> selectPage(Page<HkOvertimeCollect> page, HkOvertimeCollect hkOvertimeCollect) {
        QueryWrapper<HkOvertimeCollect> query = Wrappers.query();
        QueryWrapper<HkOvertimeCollect> entityWrapper = getEntityWrapper(query, hkOvertimeCollect);
        return hkOvertimeCollectMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HkOvertimeCollect> selectList(HkOvertimeCollect hkOvertimeCollect) {
        QueryWrapper<HkOvertimeCollect> query = Wrappers.query();
        QueryWrapper<HkOvertimeCollect> entityWrapper = getEntityWrapper(query, hkOvertimeCollect);
        return hkOvertimeCollectMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HkOvertimeCollect> getEntityWrapper(QueryWrapper<HkOvertimeCollect> entityWrapper, HkOvertimeCollect hkOvertimeCollect) {
        //条件拼接
        if (StringUtils.isNotBlank(hkOvertimeCollect.getHontUserId())) {
            entityWrapper.like(HkOvertimeCollect.HONT_USER_ID, hkOvertimeCollect.getHontUserId());
        }

        if (StringUtils.isNotBlank(hkOvertimeCollect.getDateMoth())) {
            entityWrapper.like(HkOvertimeCollect.DATE_MOTH, hkOvertimeCollect.getDateMoth());
        }
        if (StringUtils.isNotBlank(hkOvertimeCollect.getCreateBy())) {
            entityWrapper.like(HkOvertimeCollect.CREATE_BY, hkOvertimeCollect.getCreateBy());
        }
        if (StringUtils.isNotBlank(hkOvertimeCollect.getUpdateBy())) {
            entityWrapper.like(HkOvertimeCollect.UPDATE_BY, hkOvertimeCollect.getUpdateBy());
        }
        return entityWrapper;
    }
}
